<?php 
class ControllerPagePage extends Controller {  
	public function index() { 
		$this->language->load('page/page');
		
		$this->load->model('page/page');
		
		$this->load->model('tool/image'); 
					
		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),
       		'separator' => false
   		);	
			
		if (isset($this->request->get['path'])) {
			$path = '';
		
			$parts = explode('_', (string)$this->request->get['path']);
		
			foreach ($parts as $path_id) {
				if (!$path) {
					$path = $path_id;
				} else {
					$path .= '_' . $path_id;
				}
									
				$page_info = $this->model_page_page->getPage($path_id);
				
				if ($page_info) {
	       			$this->data['breadcrumbs'][] = array(
   	    				'text'      => $page_info['title'],
						'href'      => $this->url->link('page/page', 'path=' . $path),
        				'separator' => $this->language->get('text_separator')
        			);
				}
			}		
		
			$page_id = array_pop($parts);
		} else {
			$page_id = 1;
		}
		
		$page_info = $this->model_page_page->getPage($page_id);
	
		if ($page_info) {
	  		$this->document->setTitle($page_info['title']);
			$this->document->setDescription($page_info['meta_description']);
			$this->document->setKeywords($page_info['meta_keyword']);
			
			$this->data['heading_title'] = $page_info['title'];
			$this->data['print'] = $this->language->get('text_print');
			
			$this->data['content'] = html_entity_decode($page_info['content'], ENT_QUOTES, 'UTF-8');
			
			
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/page/page.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/page/page.tpl';
			} else {
				$this->template = 'default/template/page/page.tpl';
			}
			
			$this->children = array(
				'common/header',
				'common/column_left',
				'common/footer'
			);
				
			$this->response->setOutput($this->render());										
    	} else {
			$url = '';

			if(isset($this->request->get['path'])) {
				$url .= '&path=' . $this->request->get['path'];
			}
			
			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_error'),
				'href'      => $this->url->link('page/page', $url),
				'separator' => $this->language->get('text_separator')
			);
				
			$this->document->setTitle($this->language->get('text_error'));

      		$this->data['heading_title'] = $this->language->get('text_error');

      		$this->data['text_error'] = $this->language->get('text_error');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}
			
			$this->children = array(
				'common/column_left',
				'common/header'
			);
					
			$this->response->setOutput($this->render());
		}
  	}
}
?>